#include "view_time_16.h"
#include "view_time_16.inc"
#include "view_time_14.h"
#include "view_time_3.h"
#include "view_time_0.h"
#include "display_ctrl.h"
#include "platform_assert.h"
#include "lfs_file_manager_auto.h"
#include "rtc.h"
#include "datetime.h"
#include "blecom.h"
#include "battery_ctrl.h"
#include "sport_his.h"
#include "display_ctrl.h"
#include "display_interface_240x240.h"
#include "datetime.h"
#include "heart_rate_interface.h"
#include "font/num_font.h"
#include "font_mngr.h"
#include "view_common.h"
#include "app_trace.h"
#include "view_times.h"
#include "math.h"
#include "weather_ctrl.h"
#include "health_storage.h"
#include "app_trace.h"
#define LOG(fmt, ...) app_trace_log(fmt "\r\n", ##__VA_ARGS__)
#ifdef TIME_16_SKIP
#else
void view_time_16_display(void)
{
    bool ble_connect = disp_ctrl.com_data.i_temp[6];
    uint8_t battery_level = disp_ctrl.com_data.i_temp[7];
    bool is_charge = disp_ctrl.com_data.i_temp[8];
    int steps = disp_ctrl.com_data.i_temp[11];
    int calories = disp_ctrl.com_data.i_temp[16];
    int heart_rate = disp_ctrl.com_data.i_temp[17];
    int hour_type = disp_ctrl.com_data.i_temp[9];
    int x = 88;
    int y = 7;
    if (ble_connect)
    {
        disp_draw_user_image(x, y, bmp_1101_connect);
    }
    else
    {
        disp_draw_user_image(x, y, bmp_1102_noconnect);
    }
    x = 123;
    y = 9;

    if (is_charge)
    {
        disp_ctrl.auto_refresh_time = 500;
        battery_level = disp_ctrl.auto_refresh_count % 5;
        _disp_show_flash_img(DISP_LFS_FILE_INDEX_0, x, y, FILE_IMG_1103_electricity_100 + 4 - battery_level);
    }
    else
    {
        disp_ctrl.auto_refresh_time = 1000;
        _disp_show_flash_img(DISP_LFS_FILE_INDEX_0, x, y, FILE_IMG_1103_electricity_100 + 4 - battery_level);
    }
    x = 39;
    y = 37;
    int percent = steps * 100 / system_config_get_target_step();
    uint8_t const *base = bmp_1108_step_ring_dark;
    uint8_t const *full = bmp_1109_step_ring_bright;
    disp_draw_user_image(x, y, base);
    disp_draw_user_image_percent_circle(x, y, full, percent, 41);
    x = 53;
    y = 51;
    disp_draw_user_image(x, y, bmp_1116_step_icon);

    x = 98;
    y = 37;
    percent = calories * 100 / system_config_get_target_calorie();
    base = bmp_1110_calories_ring_dark;
    full = bmp_1111_caloties_ring_bright;
    disp_draw_user_image(x, y, base);
    disp_draw_user_image_percent_circle(x, y, full, percent, 41);
    x = 112;
    y = 51;
    disp_draw_user_image(x, y, bmp_1115_caloties_icon);

    x = 156;
    y = 37;
    int max_heart_rate = 220 - system_config_get_age();
    int min_heart_rate = 40;
    percent = (heart_rate - min_heart_rate) * 100 / (max_heart_rate - min_heart_rate);
    base = bmp_1112_heartrate_ring_dark;
    full = bmp_1113_heartrate_ring_bright;
    disp_draw_user_image(x, y, base);
    disp_draw_user_image_percent_circle(x, y, full, percent, 41);
    x = 170;
    y = 52;
    disp_draw_user_image(x, y, bmp_1114_heartrate_icon);

    int x_offset = 0;
    if (hour_type == 0)
    {
        x_offset = 17;
    }
    x = 20 + x_offset;
    y = 98;
    _disp_show_flash_img(DISP_LFS_FILE_INDEX_1, x, y, FILE_IMG_1124_time_0_30x55 + disp_ctrl.com_data.i_temp[5] / 10);

    x = 60 + x_offset;
    _disp_show_flash_img(DISP_LFS_FILE_INDEX_2, x, y, FILE_IMG_1124_time_0_30x55 + disp_ctrl.com_data.i_temp[5] % 10);

    x = 122 + x_offset;
    _disp_show_flash_img(DISP_LFS_FILE_INDEX_3, x, y, FILE_IMG_1124_time_0_30x55 + disp_ctrl.com_data.i_temp[6] / 10);

    x = 162 + x_offset;
    _disp_show_flash_img(DISP_LFS_FILE_INDEX_4, x, y, FILE_IMG_1124_time_0_30x55 + disp_ctrl.com_data.i_temp[6] % 10);

    x = 103 + x_offset;
    disp_draw_user_image(x, y, bmp_1137_time_second);

    x = 196;
    y = 142;
    if (hour_type == 1)
    {
        disp_draw_user_image(x, y, bmp_1135_time_am);
    }
    else if (hour_type == 2)
    {
        disp_draw_user_image(x, y, bmp_1136_time_pm);
    }

    x = 49;
    y = 175;
    disp_draw_user_image(x, y, bmp_1134_frame);

    x = 144;
    y = 188;
    _disp_show_flash_img(DISP_LFS_FILE_INDEX_5, x, y, FILE_IMG_1117_week_mon + disp_ctrl.com_data.i_temp[11] - 1);

    x = 64;
    y = 187;
    disp_draw_user_image(x, y, num_1140_date_8x17_TAB[(disp_ctrl.com_data.i_temp[8] % 100) / 10]);

    x = 74;
    disp_draw_user_image(x, y, num_1140_date_8x17_TAB[disp_ctrl.com_data.i_temp[8] % 10]);

    x = 89;
    disp_draw_user_image(x, y, num_1140_date_8x17_TAB[disp_ctrl.com_data.i_temp[9] / 10]);
    x = 99;
    disp_draw_user_image(x, y, num_1140_date_8x17_TAB[disp_ctrl.com_data.i_temp[9] % 10]);
    x = 114;
    disp_draw_user_image(x, y, num_1140_date_8x17_TAB[disp_ctrl.com_data.i_temp[10] / 10]);
    x = 124;
    disp_draw_user_image(x, y, num_1140_date_8x17_TAB[disp_ctrl.com_data.i_temp[10] % 10]);
    x = 84;
    // y = 201;
    disp_draw_user_image(x, y, num_1140_date_8x17_point);
    x = 108;
    disp_draw_user_image(x, y, num_1140_date_8x17_point);
}
#endif
